﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>施工单模板维护</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style>
        .easyui-linkbutton{margin-left:20px;}
        table tr td{padding:0px 5px}
       #fm .l-btn-text{margin-top:3px}
    </style>
</head>
<body>
 <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>施工单模板名称:</td>
	    		</tr>
	    		<tr>
	    			<td><input  name="templateName" class="easyui-textbox" style="width: 120px; height: 22px" id="templateName"/></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
	    		</tr>
	    	</table>
	    </form>
        </div> 
    </div>
    <div class="panelSection">
          <div class="easyui-panel " title="施工单模板基础信息" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <table id="AssemWorkFlowTemplate" style="height:240px" data-options="rownumbers:true"></table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
                    </div>
             <div style="margin-top:7px">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.appendRow('AssemWorkFlowTemplate',{ASSEMWORKFLOWTEMPLATEID:'',TEMPLATENAME:'',NOTE:''})">新增模板</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.acceptTemplate()">保存模板</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleteTemplate()">删除模板</a>
                <a href="/InSiteWebApplication/Temp2/导入模板/施工单维护导入模板.xlsx" class="easyui-linkbutton">模板下载</a>
                <form id="fm" method="post" enctype="multipart/form-data" style="display:inline-block;margin-left:20px;">
                    <input class="easyui-filebox" id="fileUpload" name="fileUpload" style="width:68px;height: 24px;line-height: 24px;" data-options="buttonText:'导入模板',onChange:function(n,o){page.easyuiUpload(n,o);}"/>
                </form>
                <span style="color:red;font-weight:bold;margin-left: 10px;">内部系统，禁止处理涉密信息！</span>
             </div>
             </div>
    </div>
    <div class="panelSection">
        <div class="panelSection" style="float:left;width:970px"><table id="specInfo" style="height:240px;width:100%" data-options="title:'施工单工序信息'"></table></div>
        <table id="stepInfo" style="height:240px;float:left;width:100%-970px" data-options="title:'施工单工步信息'"></table>
    </div>
    <div style="margin-top:10px;">
        <div style="float:left;width:970px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.appendRow('specInfo',{ASSEMWORKFLOWTEMPLATESPECID:'',ASSEMWORKFLOWTEMPLATEID:''})">新增工序</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.acceptSpec()">保存工序</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleteSpec()">删除工序</a>
        </div>
        <div style="float:left">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.appendRow('stepInfo',{ASSEMWORKFLOWTEMPLATEStepID:''})">新增工步</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.acceptStep()">保存工步</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleteStep()">删除工步</a>
        </div>
    </div>
    <div style="clear:both"></div>
     <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    //创建人：longb
    //日期：2023-06-25
    //描述：排故单附页查看
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        editIndex:undefined,
        team:null,
        workcenter:null,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSAssemWorkFlowHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
        },
        endEditing:function(id){
             if (page.editIndex == undefined){return true}   
             if ($('#'+id).datagrid('validateRow', page.editIndex)){
				var ed = $('#'+id).datagrid('getEditor', {index:page.editIndex});
				$('#'+id).datagrid('endEdit', page.editIndex);
				page.editIndex = undefined;
				return true;
			} else {
				return false;
			}
        },
        //页面事件绑定
        bind: function () {
            $('#AssemWorkFlowTemplate').datagrid({
                checkOnSelect: true,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                 { field: 'TEMPLATENAME', title: '模板名称', width: 150,editor:'textbox' },
                 { field: 'CREATENAME', title: '创建人', width: 100 },
		         { field: 'CREATEDATE', title: '创建时间', width: 150 },
                 { field: 'UPDATENAME', title: '修改人', width: 100 },
                 { field: 'UPDATEDATE', title: '修改时间', width: 150 },
                 { field: 'NOTE', title: '备注', width: 450,editor:'textbox' }
                ]],
                onClickRow:function(index,row){
                    page.onClickRow(index,'AssemWorkFlowTemplate');
                    page.getAssemWorkFlowSpec(row);
                    page.getAssemWorkFlowStep(row.ASSEMWORKFLOWTEMPLATEID,null);
                },
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.getTemlateData(null);
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.getTemlateData(null);
            });

            $('#specInfo').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                singleSelect: true,
                columns: [[
                 {field:'ck',checkbox:true},
                 { field: 'SPECNO', title: '工序号', width: 70,formatter: function(value,row,index){if(value==null){return index+1;}else if((index+1)!=row.SPECNO){return index+1;}else{return value;}}  },
                 { field: 'WORKCENTERID', title: '工区', width: 100,formatter:function(value,row){return row.WORKCENTERNAME;},
                 editor:{type:'combobox',options:{valueField:'WORKCENTERID',textField:'WORKCENTERNAME',method:'get',url:page.ajaxUrl+"?action=GetWorkCenter"
                    ,onSelect:function(r){
                        $('#specInfo').datagrid('getRows')[page.editIndex]['WORKCENTERNAME'] =r.WORKCENTERNAME; 
                        $('#specInfo').datagrid('getRows')[page.editIndex]['WORKCENTERID'] =r.WORKCENTERID;
                        var ed2 = $('#specInfo').datagrid('getEditor',{ 'index': page.editIndex, field: 'TEAMID' });
                        if(r.WORKCENTERID!=""){$(ed2.target).combobox('disable');}else{$(ed2.target).combobox('enable');}
                    }
                 }} },
		         { field: 'TEAMID', title: '组', width: 100,formatter:function(value,row){return row.TEAMNAME;},
                 editor:{type:'combobox',options:{valueField:'TEAMID',textField:'TEAMNAME',method:'get',url:page.ajaxUrl+"?action=GetTeam"
                  ,onSelect:function(r){
                    $('#specInfo').datagrid('getRows')[page.editIndex]['TEAMNAME'] =r.TEAMNAME; 
                    $('#specInfo').datagrid('getRows')[page.editIndex]['TEAMID'] =r.TEAMID;
                    var ed2 = $('#specInfo').datagrid('getEditor',{ 'index': page.editIndex, field: 'WORKCENTERID' });
                    if(r.TEAMID!=""){$(ed2.target).combobox('disable');}else{$(ed2.target).combobox('enable');}
                  }
                 }} },
                 { field: 'SPECNAME', title: '工序', width: 100,editor:'textbox' },
                 { field: 'SPECDESC', title: '工序描述', width: 250,editor:'textbox' },
                 { field: 'WORKSTATIONIDS', title: '工位', width: 100,formatter:function(value,row){return row.WORKSTATIONNAME;},
                    editor:{type:'combobox',options:{valueField:'WORKSTATIONID',textField:'WORKSTATIONNAME',panelHeight:'auto',multiple:true,method:'get',
                    url:page.ajaxUrl+"?action=GetWorkStations",onSelect:function(r){
                         var ed2 = $('#specInfo').datagrid('getEditor',{ 'index': page.editIndex, field: 'WORKSTATIONIDS' });
                         var allData=$(ed2.target).combobox('getData');
                         var values=$(ed2.target).combobox('getValues');
                         var w=[];
                         for(var j=0;j<=values.length;j++){
                            $.each(allData,function(index,item){
                                if(values[j]==item.WORKSTATIONID){
                                    w.push(item.WORKSTATIONNAME);
                                }
                            });
                         }
                         w.push(r.WORKSTATIONNAME);
                        $('#specInfo').datagrid('getRows')[page.editIndex]['WORKSTATIONIDS'] =$(ed2.target).combobox('getValues');
                        $('#specInfo').datagrid('getRows')[page.editIndex]['WORKSTATIONNAME'] =w.join(',');
                        $(ed2.target).combobox('setValues',$(ed2.target).combobox('getValues'))
                    }
                    }}
                  },
                  { field: 'PREPARECYCLE', title: '准备时间(分钟)', width: 100,editor:'numberbox' },
                  { field: 'MAKECYCLE', title: '加工时间(分钟)', width: 100,editor:'numberbox' },
                  { field: 'TRANSFERCYCLE', title: '运转时间(分钟)', width: 100,editor:'numberbox' },
                  { field: 'CHANGEOVERCYCLE', title: '换型时间(分钟)', width: 100,editor:'numberbox' }
                ]],
                onClickRow:function(index,row){
                    page.onClickRow(index,'specInfo');
                    page.getAssemWorkFlowStep(row.ASSEMWORKFLOWTEMPLATEID,row.ASSEMWORKFLOWTEMPLATESPECID);
                }
            });
            $('#stepInfo').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                columns: [[
                 {field:'ck',checkbox:true},
                 { field: 'STEPNO', title: '工步号', width: 100,formatter: function(value,row,index){if(value==null){return index+1;}else{return value;}} },
                 { field: 'STEPNAME', title: '工步内容', width: 300,editor:'textbox' }
                ]],
                onClickRow:function(index){
                    page.onClickRow(index,'stepInfo');
                }
            });
        },
        //查询
        searchData: function () {
            clearMessage();
            page.pageNumber = 1;
            page.getTemlateData(null);
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            clearMessage();
        },
        getTemlateData:function(index){
            $('#specInfo').datagrid('loadData',[]);
            $('#stepInfo').datagrid('loadData',[]);
            var param = {
                action: "GetAssemWorkFlowTemplate",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                templateName: $('#templateName').textbox('getValue')
            };
            page.post(param, function (res) {
                if (res.Result) {
                    page.pagetotal = res.RowCount;
                    $('#AssemWorkFlowTemplate').datagrid('loadData', res.DBTable);
                    if(index!=null){$('#AssemWorkFlowTemplate').datagrid('selectRow',index);}
                }
            });
        },
        //查询施工单模板工序信息
        getAssemWorkFlowSpec: function (row) {
         $('#specInfo').datagrid('loadData',[]);
            var param = {
                action: "GetAssemWorkFlowSpec",
                tid: row.ASSEMWORKFLOWTEMPLATEID
            };
            page.post(param, function (res) {
                $('#specInfo').datagrid('loadData', res);
                if(res.length>0){$('#specInfo').datagrid('selectRow',0);}
            });
        },
        //查询施工单模板工步信息
        getAssemWorkFlowStep: function (tid,specid) {
         $('#stepInfo').datagrid('loadData',[]);
         if(tid==""&&(specid==""||specid==null)){return;}
            var param = {
                action: "GetAssemWorkFlowStep",
                tid: tid,
                specid:specid
            };
            page.post(param, function (res) {
                $('#stepInfo').datagrid('loadData', res);
            });
        },
        deleteTemplate:function(){
            var row=$('#AssemWorkFlowTemplate').datagrid('getSelected');
            if(row==null){displayMessage('请选择一条模板信息再进行操作',false);return;}
            page.post({action:'DeleteAssemWorkFlowTemplate',ids:row.ASSEMWORKFLOWTEMPLATEID}, function (res) {
                 if(res.Result){
                   page.getTemlateData();
                   $('#specInfo').datagrid('loadData',[]);
                   $('#stepInfo').datagrid('loadData',[]);
                 }
                 displayMessage(res.Message, res.Result);
            })
        },
        //删除工序
        deleteSpec:function(){
            var rows=$('#specInfo').datagrid('getChecked');
            if(rows.length==0){displayMessage('请勾选至少一条工序信息再进行操作',false);return;}
            var tRow=$('#AssemWorkFlowTemplate').datagrid('getSelected');
            var ids=[];
            $.each(rows,function(index,item){
                ids.push(item.ASSEMWORKFLOWTEMPLATESPECID);
            });
            page.post({action:'DeleteAssemWorkFlowSpec',ids:ids.join(','),tid:tRow.ASSEMWORKFLOWTEMPLATEID}, function (res) {
                 if(res.Result){
                   page.getAssemWorkFlowSpec(tRow);
                   $('#stepInfo').datagrid('loadData',[]);
                 }
                 displayMessage(res.Message, res.Result);
            })
        },
        deleteStep:function(){
            var rows=$('#stepInfo').datagrid('getChecked');
            if(rows.length==0){displayMessage('请勾选至少一条工步信息再进行操作',false);return;}
            var specRow=$('#specInfo').datagrid('getSelected');
            var ids=[];
            $.each(rows,function(index,item){
                ids.push(item.ASSEMWORKFLOWTEMPLATESTEPID);
            });
            page.post({action:'DeleteAssemWorkFlowStep',ids:ids.join(','),specid:specRow.ASSEMWORKFLOWTEMPLATESPECID}, function (res) {
                if(res.Result){page.getAssemWorkFlowStep(null,specRow.ASSEMWORKFLOWTEMPLATESPECID);}
                 displayMessage(res.Message, res.Result);
            })
        },
        ///模板保存
        acceptTemplate:function(){
            $('#AssemWorkFlowTemplate').datagrid('endEdit',page.editIndex);
            var rows= $('#AssemWorkFlowTemplate').datagrid('getChanges');
            var param = {
                action: "SaveAssemWorkFlowTemplate",
                data:JSON.stringify(rows)
                }
           page.post(param, function (res) {
                if (res.Result) {
                    page.getTemlateData();
                }
                displayMessage(res.Message, res.Result);
           });
        },
        //保存工序
        acceptSpec:function(){
            $('#specInfo').datagrid('endEdit',page.editIndex);
            var rows= $('#specInfo').datagrid('getRows');//getChanges
            var trow=$('#AssemWorkFlowTemplate').datagrid('getSelected');

            var param = {
                action: "SaveAssemWorkFlowSpec",
                data:JSON.stringify(rows),
                tid:trow.ASSEMWORKFLOWTEMPLATEID
                }
           page.post(param, function (res) {
                if (res.Result) {
                    page.getAssemWorkFlowSpec($('#AssemWorkFlowTemplate').datagrid('getSelected'));
                }
                displayMessage(res.Message, res.Result);
           });
        },
        //保存工步
        acceptStep:function(){
            $('#stepInfo').datagrid('endEdit',page.editIndex);
            var rows= $('#stepInfo').datagrid('getChanges');
            var specrow=$('#specInfo').datagrid('getSelected');
            var param = {
                action: "SaveAssemWorkFlowStep",
                data:JSON.stringify(rows),
                specid:specrow.ASSEMWORKFLOWTEMPLATESPECID
                }
           page.post(param, function (res) {
                if (res.Result) {
                    page.getAssemWorkFlowStep(null,specrow.ASSEMWORKFLOWTEMPLATESPECID);
                }
                displayMessage(res.Message, res.Result);
           });
        },
        appendRow:function(id,columns){
            if(id=="specInfo"){
                var trow=$('#AssemWorkFlowTemplate').datagrid('getSelected');
                if(trow==null){displayMessage('请选择一条模板记录再进行操作',false);return;}
                if(trow.ASSEMWORKFLOWTEMPLATEID==""){displayMessage('请选择一条已保存的模板记录再进行操作',false);return;}
                $('#stepInfo').datagrid('loadData',[]);
            }
            if(id=="stepInfo"){
                var specRow=$('#specInfo').datagrid('getSelected');
                if(specRow==null){displayMessage('请选择一条工序记录再进行操作',false);return;}
                if(specRow.ASSEMWORKFLOWTEMPLATESPECID==""){displayMessage('请选择一条已保存的工序记录再进行操作',false);return;}
            }
            if(id=="AssemWorkFlowTemplate"){
                 $('#stepInfo').datagrid('loadData',[]);
                 $('#specInfo').datagrid('loadData',[]);
            }
            $('#AssemWorkFlowTemplate').datagrid('endEdit',page.editIndex);
            $('#specInfo').datagrid('endEdit',page.editIndex);
            $('#stepInfo').datagrid('endEdit',page.editIndex);
            if (page.endEditing(id)){
				$('#'+id).datagrid('appendRow',columns);
				page.editIndex = $('#'+id).datagrid('getRows').length-1;
                if(id=="specInfo"){
                   var specInfo= $('#'+id).datagrid('getRows')[page.editIndex];
                    specInfo['SPECNO'] = page.editIndex+1;
                    specInfo['PREPARECYCLE']=0;
                    specInfo['MAKECYCLE']=0;
                    specInfo['TRANSFERCYCLE']=0;
                    specInfo['CHANGEOVERCYCLE']=0;
                    }
                if(id=="stepInfo"){$('#'+id).datagrid('getRows')[page.editIndex]['STEPNO'] =page.editIndex+1; }
				$('#'+id).datagrid('selectRow', page.editIndex).datagrid('beginEdit', page.editIndex);
			}
        },
        onClickRow:function(index,id){
            $('#AssemWorkFlowTemplate').datagrid('endEdit',page.editIndex);
            $('#specInfo').datagrid('endEdit',page.editIndex);
            $('#stepInfo').datagrid('endEdit',page.editIndex);
            page.editIndex=undefined;
            if (page.editIndex != index){
				if (page.endEditing(id)){
					$('#'+id).datagrid('selectRow', index).datagrid('beginEdit', index);
					page.editIndex = index;
				} else {
					$('#'+id).datagrid('selectRow', page.editIndex);
				}
			}
        },
        easyuiUpload: function (n,o) {
            if(o!=""){return;}
            if ($('#fileUpload').filebox('getValue') != "") {
                clearMessage();
                $('#fm').form('submit', {
                    url: page.ajaxUrl + "?action=ImportAssemWorkFlowTemplate",
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        $('#fileUpload').filebox('clear');
                        var res = JSON.parse(result); 
                        if(res.Result){page.getTemlateData();}
                        displayMessage(res.Message, res.Result);
                    }
                });
            }
        },
        //post数据
        post: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        },
        postasync: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    //$.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
